home *** CD-ROM | disk | FTP | other *** search
- /* This example use of imageprocess.library loads the image file specified
- on the command line at half size and performs autogamma on it and views
- it halved in size in a guigfx window.
- */
-
- #include <stdio.h>
-
- #include <dos/dos.h>
- #include <exec/memory.h>
- #include <exec/types.h>
-
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
-
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/intuition_pragmas.h>
-
- #include <imageio/imageio.h>
- #include <imageio/imageio_protos.h>
- #include <imageio/imageio_pragmas.h>
-
- #include <imageprocess/imageprocess.h>
- #include <imageprocess/imageprocess_protos.h>
- #include <imageprocess/imageprocess_pragmas.h>
-
- #include <guigfx/guigfx.h>
- #include <pragmas/guigfx_pragmas.h>
- #include <guigfx/guigfx_protos.h>
-
- /* Function prototypes */
- __saveds __asm ULONG progressFunc( register __d0 ULONG curr, register __d1 ULONG lines, register __a0 void *userdata );
- void DisplayGuiGfx( UBYTE *buffer, UBYTE cs, ULONG bpp, ULONG x, ULONG y );
-
- extern struct Library *DOSBase;
- struct Library *ImageIOBase, *IntuitionBase, *ImageProcessBase;
-
- void main( int argc, char **argv )
- {
- if ( argv[1] )
- {
- ImageIOBase = OpenLibrary( "imageio.library", 2 );
- ImageProcessBase = OpenLibrary( "imageprocess.library", 1 );
- IntuitionBase = OpenLibrary( "intuition.library", NULL );
- if ( IntuitionBase && ImageIOBase && ImageProcessBase )
- {
- struct ImageHandle *ih;
- ULONG err;
-
- err = AllocImage( &ih,
- IMG_SrcFilename, argv[1],
- TAG_DONE );
- if ( !err )
- {
- ULONG num = 1, denom = 2;
- ULONG x, y, bpp;
- UBYTE *buffer, cs;
- int prevpercent;
-
- err = GetImageAttrs( ih,
- IMG_Width, &x,
- IMG_Height,&y,
- IMG_BytesPerPixel, &bpp,
- IMG_ColourSpace, &cs,
- IMG_TestScaleNum, num,
- IMG_TestScaleDenom, denom,
- TAG_DONE );
- if ( !err )
- {
- printf( "width=%ld, height=%ld\n", x, y );
- printf( "bytes per pixel=%ld, colourspace=%d\n", bpp, cs );
-
- prevpercent = 0;
-
- err = ReadImage( ih,
- IMG_ScaleNum, num,
- IMG_ScaleDenom, denom,
- IMG_ImageBuffer, &buffer,
- IMG_ProgressHook, progressFunc,
- IMG_ProgressUserData, &prevpercent,
- TAG_DONE );
- if ( !err )
- {
- ULONG iperr;
-
- printf("imageprocess.library\n");
-
- iperr = DoImageProcess( IMP_Process_AutoGamma,
- IMP_SourceImageIOHandle, ih,
- IMP_GammaMode, GAMMA_FAST,
- TAG_DONE );
- if ( !iperr )
- {
- printf("%ld x %ld\n",x,y);
-
- err = GetImageAttrs( ih,
- IMG_ImageBuffer, &buffer,
- TAG_DONE );
- if ( !err )
- {
- DisplayGuiGfx( buffer, cs, bpp, x, y );
- }
- }
- else printf( "doimageprocess error:%ld\n", iperr );
- }
- else printf( "read image error:%d\n", err );
- }
- else printf( "get image attrs error:%d\n", err );
-
- FreeImage( ih );
- }
- else printf( "alloc image error:%d\n", err );
- }
-
- if ( ImageIOBase ) CloseLibrary( ImageIOBase );
- if ( ImageProcessBase ) CloseLibrary( ImageProcessBase );
- if ( IntuitionBase ) CloseLibrary ( IntuitionBase );
- }
- }
-
- __saveds __asm ULONG progressFunc( register __d0 ULONG curr, register __d1 ULONG lines, register __a0 void *userdata )
- {
- int *prevpercent = (int *)userdata;
-
- int percent = ( curr * 100 ) / lines;
-
- if ( *prevpercent != percent )
- {
- if ( percent % 10 == 0 ) printf( "%d%%\n", percent );
- }
-
- *prevpercent = percent;
-
- return NULL;
- }
-
- void DisplayGuiGfx( UBYTE *buffer, UBYTE cs, ULONG bpp, ULONG x, ULONG y )
- {
- struct Library *GuiGFXBase;
-
- GuiGFXBase = OpenLibrary( "guigfx.library", NULL );
- if ( GuiGFXBase )
- {
- struct Window *win;
- APTR dh, pi;
-
- win = OpenWindowTags( NULL,
- WA_Title, "Proof",
- WA_Flags, WFLG_ACTIVATE | WFLG_SIMPLE_REFRESH |
- WFLG_SIZEGADGET | WFLG_RMBTRAP | WFLG_DRAGBAR |
- WFLG_DEPTHGADGET | WFLG_CLOSEGADGET,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
- IDCMP_SIZEVERIFY | IDCMP_NEWSIZE | IDCMP_RAWKEY,
- WA_Left, 16,
- WA_Top, 16,
- WA_Width, x,
- WA_Height, y,
- TAG_DONE );
-
- if ( win != NULL )
- {
- dh = ObtainDrawHandle( NULL, win->RPort, win->WScreen->ViewPort.ColorMap, TAG_DONE );
-
- if ( dh )
- {
- UBYTE *newbuffer;
- ULONG iperr, newbuffersize;
-
- iperr = DoImageProcess( IMP_Process_SwapColourSpace,
- IMP_NewColourSpace, IMCS_ARGB,
- IMP_SourceBuffer, buffer,
- IMP_SourceWidth, x,
- IMP_SourceHeight, y,
- IMP_SourceBytesPerPixel, bpp,
- IMP_SourceColourSpace, cs,
- IMP_Buffer, &newbuffer,
- IMP_BufferSize, &newbuffersize,
- TAG_DONE );
- if ( !iperr )
- {
- pi = MakePicture( newbuffer, x, y, GGFX_PixelFormat, PIXFMT_0RGB_32, TAG_DONE );
- if ( pi )
- {
- struct Message *msg;
-
- DrawPicture( dh, pi, 0, 0, NULL );
-
- Wait( 1L << win->UserPort->mp_SigBit );
-
- while ( ( msg = GetMsg( win->UserPort ) ) != NULL ) ReplyMsg( msg );
-
- DeletePicture( pi );
- }
- else printf( "failed to create picture\n" );
-
- FreeMem( newbuffer, newbuffersize );
- }
- else printf( "pic imageprocess err:%ld\n", iperr );
-
- ReleaseDrawHandle( dh );
- }
- else printf( "failed to get drawhandle\n" );
-
- CloseWindow( win );
- }
- else printf( "failed to open window\n" );
- }
- else printf( "failed to open guigfx.library\n" );
-
- if ( GuiGFXBase ) CloseLibrary( GuiGFXBase );
- }
-